<template>
    <scroll-view 
        :scroll-y="true"
        class="xbl_cp">
        <view class="container">
            <u-form 
                :model="form" 
                ref="uForm" 
                label-width="fit-content">
                <view class="one">
                    <view class="top">
                        <u-form-item label="姓名">
                            <u-input :placeholder="String(user.name)" :disabled="true"/>
                        </u-form-item>
                        <u-form-item label="年龄">
                            <u-input :placeholder="String(user.age)" :disabled="true"/>
                        </u-form-item>
                    </view>
                    <u-form-item label="初步诊断" prop="bing" :label-width="150">
                        <SelectOfficeTwoInputCp
                            v-model="form.bing">   
                        </SelectOfficeTwoInputCp>
                    </u-form-item>
                </view>
                <view class="two">
                    <u-form-item label="主诉" prop="zhusu" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.zhusu" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="现病史" prop="xianbingshi" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.xianbingshi" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="既往病史" prop="jiwangbingshi" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.jiwangbingshi" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="过敏史" prop="guominshi" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.guominshi" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="个人史" prop="gerenshi" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.gerenshi" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="家庭史" prop="jiatingshi" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.jiatingshi" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="体检" prop="tijian" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.tijian" type="textarea" :auto-height="true"/>
                    </u-form-item>
                    <u-form-item label="辅助检查" prop="fuzhu" label-position="top" :border-bottom="false" :label-style="{lineHeight:1}">
                        <u-input v-model="form.fuzhu" type="textarea" :auto-height="true"/>
                    </u-form-item>
                </view>
                <u-form-item label="治疗建议" prop="zhiliaojianyi" label-position="top">
                    <u-input v-model="form.zhiliaojianyi" type="textarea" :auto-height="true"/>
                </u-form-item>
                <view class="bt_list">
                    <u-button 
                        type="success"
                        :ripple="true"
                        shape="circle"
                        @click="addData">
                        确定
                    </u-button>
                    <u-button 
                        type="error"
                        :ripple="true"
                        shape="circle"
                        @click="removeForm">
                        初始化
                    </u-button>
                </view>
            </u-form>
            <u-toast ref="uToast" />
        </view>
    </scroll-view>
</template>

<script>
//写病历
import SelectOfficeTwoInputCp from "@/components/public/SelectOfficeTwoInput";
import {addBingLi} from "@/common/api"
export default {
    components:{SelectOfficeTwoInputCp},
    props:{
        user:{ //病人数据
            type:Object,
            default:()=>{
                return {};
            },
        },
        Rid:{ //挂号单
            type:String,
            default:'',
        },
        show:{ //当前滑块时候显示
            type:Boolean,
            default:false,
        },
    },    
    data() {
        return {
            form: {
                bing: '',
                zhusu: '',
                xianbingshi: '',
                jiwangbingshi:'',
                guominshi:'',
                gerenshi:'',
                jiatingshi:'',
                tijian:'',
                fuzhu:'',
                zhiliaojianyi:'',
            },
            //数据验证规则
            rules:{
            	bing:[
            		{
            			required: true,
            			message: '不能为空',
            			trigger: ['blur', 'change'],
            		}
            	],                
            },
        }
    },
    onReady() {
    	this.$refs.uForm.setRules(this.rules);
    },
    methods: {
        addData(){ //添加写病历数据
            this.$refs.uForm.validate(valid => {
                if (valid) {
                    if(!this.user.name){
                        this.$refs.uToast.show({
                            title: "请选择病人",
                            position:'top',
                            type: 'error',
                        });
                        return;
                    }
                    addBingLi(
                        {
                            ...this.form,
                            Rid:this.Rid,
                            kid:this.user.kid,
                        },
                    ).then(data=>{
                        this.$refs.uToast.show({
                            title: '添加成功',
                            position:'top',
                            type: 'success',
                        });
                    }).catch(msg=>{
                        this.$refs.uToast.show({
                            title: msg,
                            position:'top',
                            type: 'error',
                        });
                    });
                }
            });
        },
        removeForm(){ //清空表单
            this.$refs.uForm.resetFields();
            for(let index in this.form){
                this.form[index] = "";
            }
        },
    },
}
</script>
<style scoped lang="scss">
    .xbl_cp{
        height: calc(100vh - 90rpx);
        .container{
            padding: 35rpx;
            box-sizing: border-box;
            .one{
                padding: 0 25rpx 25rpx 25rpx;
                border-radius: 2px;
                box-sizing: border-box;
                border: 1px solid #e4ebef;
                .u-form-item{
                    width: 100%;
                }
                /deep/.u-input{
                    width: 100%;
                }
                .top{
                    display: grid;
                    grid-template-columns: 1fr 1fr;
                }
            }
            .two{
                margin-top: 35rpx;
                display: grid;
                grid-template-columns: 1fr 1fr;
                grid-gap:25rpx;
                .u-form-item{
                    width: 100%;
                    padding: 0 15rpx;
                    padding-top: 15rpx;
                    box-sizing: border-box;
                    border: 1px solid #e4ebef;
                    border-radius: 2px;
                }
            }
            .bt_list{
                margin-top: 35rpx;
                display: grid;
                grid-gap: 35rpx;
                width: 100%;
                *{
                    width:100%;
                }
            }
        }
    }
</style>
